#include "threadPool.hpp"
#include "Task.hpp"
#include "log.hpp"
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <unistd.h>

int main()
{
    logMessage(NORMAL,"%s %d %c %f \n","这是一条日志信息",1234,'c',3.14);
    // std::cout<<"hello thread pool"<<std::endl;
    srand((unsigned long)time(nullptr)^getpid());
    //ThreadPool<Task> *tp = new ThreadPool<Task>();
    //ThreadPool<Task> *tp = ThreadPool<Task>::getThreadPool(5);
    ThreadPool<Task>::getThreadPool()->run();
    //tp->run();

    //tp->joins();
    
    while(true)
    {
        int x = rand()%100+1;
        usleep(7721);
        int y = rand()%30+1;
        Task t(x, y, [](int x,int y)->int{
            return x+y;
        });

        //std::cout << "制作任务完成： "<<x<<"+"<<y<<"=?"<<std::endl;
        logMessage(DEBUG,"制作任务完成：%d+%d=?",x,y);
        // 推送任务到线程池
        ThreadPool<Task>::getThreadPool()->PushTask(t);

        sleep(1);
    }

    return 0;
}